# KERNEL ?= sgemm_x_mcblas
# KERNEL ?= sgemm_0_naive
# KERNEL ?= sgemm_1_coalesced
# KERNEL ?= sgemm_1_shared_memory
# KERNEL ?= sgemm_2_joint_tiling
# KERNEL ?= sgemm_3_loop_interchange_64x128x16_8x16_f4
# KERNEL ?= sgemm_3_loop_interchange_128x128x16_16x16_f4
# KERNEL ?= sgemm_4_bank_conflict
KERNEL ?= sgemm_5_double_buffer

CC         := mxcc 
LINKER     := $(CC)
#CFLAGS     := -O0 -g -Wall
CFLAGS     := -std=c++17 -O2 -g --resource-usage -lineinfo
CFLAGS += -w #设置警告级别为最低
LDFLAGS    := -lm  -lmcblas

UTIL       := obj/compare_matrices.o \
              obj/random_matrix.o \
              obj/sgemm_mcblas.o

TEST_OBJS  := obj/test_sgemm.o obj/$(KERNEL).o 

all: 
#	make clean;
	make bin/$(KERNEL).x

obj/%.o: %.cpp
	mkdir -p obj
	$(CC) $(CFLAGS) $(GENCODE_FLAGS)  -c $< -o $@

obj/%.o: %.maca 
	mkdir -p obj
	$(CC) $(CFLAGS) $(GENCODE_FLAGS)  -c $< -o $@


bin/$(KERNEL).x: $(TEST_OBJS) $(UTIL) Makefile
	mkdir -p bin
	$(LINKER) $(TEST_OBJS) $(UTIL) $(LDFLAGS) \
        $(BLAS_LIB) -o $(TEST_BIN) $@ 

output:	all
	mkdir -p output
	make clean;
	make all
	./bin/$(KERNEL).x  > output/$(KERNEL).csv

plot:
	python3 plot.py output

clean:
	rm -f obj/*.o *~ bin/*.x 

cleanall:
	rm -f obj/*.o *~ bin/*.x output/*.csv output/*.png ncu/*.ncu-rep

run: bin/$(KERNEL).x
	./bin/$(KERNEL).x 
	